package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.ProductCollectionContract;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.CollectionContent;
import com.boc.langxiang.manager.UserInfoManager;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/7/13.
 */
public class ProductCollectionPresenter implements ProductCollectionContract, ProductCollectionContract.Presenter {
    private View mView;

    public ProductCollectionPresenter(View view) {
        this.mView = view;
    }

    @Override
    public void collect(String id) {
        mService.collectProduct(id, UserInfoManager.getInstance().getToken())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<CollectionContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<CollectionContent> response) {
                        mView.hideLoading();
                        mView.onSuccess(response.getContent());
                    }
                });
    }
}
